<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

class CourseModel extends BaseModel {

    public function create($data) {
        if (!empty($data)) {
            return $this->save("courses", $data, "");
        }
        $this->viewModel->set("pageTitle", "Create Course");
        return $this->viewModel;
    }

    public function index() {
        $courses = $this->find_all("courses", "courses_id DESC", "", "*", "");
        $this->viewModel->set("pageTitle", "Course Manager");
        $this->viewModel->set("courses", $courses);
        return $this->viewModel;
    }

    public function edit($id,$data) {
        if (!empty($data)) {
            //return bool

            return $this->save($table = 'courses', $data = $data, $where = 'courses_id=' . $id);
        }
        
        //get item detail by id
        $course = $this->find($table = 'courses', $orderby = 'courses_id DESC', $where = 'courses_id=' . $id, $cols = '*', $limit = '');
        //param var for view
        $this->viewModel->set("pageTitle", "Update User");
        $this->viewModel->set("courses", $course);
        return $this->viewModel;
    }

}
